<template>
	<z-nav-bar :title="type ? '兑换列表' : '积分明细'"></z-nav-bar>
	<!-- <view class="text-w z-font-32 uni-mx-32 uni-my-24">2023年3月</view> -->
	<view v-if="integralList && integralList.length">
		<view v-for="integral in integralList" :key="integral.id" class="item-box">
			<view class="item flex_sbc">
				<view>
					<view>{{ integral.name }}</view>
				</view>
				<view>
					<view class="z-font-36 uni-color-main" style="text-align: right">{{ integral[type ? 'price' : 'integerNum' ] }}</view>
					<view class="uni-585C66 z-font-20">{{ integral.createTime }}</view>
				</view>
			</view>
		</view>
	</view>
	<z-no-data v-else width="400"></z-no-data>
</template>

<script setup>
import { getOrderIntegralList, getCenterIntegralList } from '@/api/integral.js';
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
import { ref, reactive, getCurrentInstance } from 'vue';
const { proxy: that } = getCurrentInstance();

const type = ref(0);
onLoad((opt) => {
	type.value = parseInt(opt.type || 0);
	console.log(type);
	fetchData();
});

const integralList = ref([]),
	params = {
		total: 0,
		pageNum: 1,
		pageSize: 10
	};
function fetchData() {
	const funName = type.value ? getOrderIntegralList : getCenterIntegralList;
	funName({ pageNum: params.pageNum, pageSize: params.pageSize }).then((res) => {
		console.log(res);
		if (type.value) integralList.value = res;
		else {
			if (params.pageNum === 1) integralList.value = res.rows;
			else integralList.value.push(...res.rows);
			params.total = res.total;
			uni.stopPullDownRefresh();
		}
	});
}
onPullDownRefresh(() => {
	params.pageNum = 1;
	fetchData();
});
onReachBottom(() => {
	if (integralList.value.length >= params.total || type.value) return;
	params.pageNum += 1;
	fetchData();
});
</script>

<style lang="scss">
page {
	background: $uni-F5F5F5;
}
</style>
<style lang="scss" scoped>
.item-box {
	width: 100vw;
	background: $uni-white;
	.item {
		width: 686rpx;
		height: 142rpx;
		border-bottom: 2rpx solid $uni-F5F5F5;
		margin-left: 32rpx;
	}
}
</style>
